package com.cisetech.web.bobocai.houtai;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cisetech.service.ColumnService;
import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.LResources;

//栏目管理控制器
@Controller
@RequestMapping(value="/column")
public class ColumnController {
	@Autowired
	ColumnService columnService;
	
	@RequestMapping(value="",method=RequestMethod.GET)
	public ModelAndView index(HttpServletResponse response,HttpServletRequest request){
		ModelAndView v = new ModelAndView("houtai/column");
		return v;
	}
	@ResponseBody
	@RequestMapping(value="/getList",method=RequestMethod.POST)
	public Page<LResources> getListAdv(LResources resources,HttpServletRequest request,HttpServletResponse response) throws Exception{
		Page<LResources> page = columnService.getList(resources);
		return page;
	}
	@RequestMapping(value="/addCoumn",method=RequestMethod.GET)
	public String addCoumn(Model v,HttpServletResponse response,HttpServletRequest request) throws Exception{
		String id = request.getParameter("id");
		LResources resources = new LResources();
		resources.setGrade("0");//最高级别
		resources.setAround("1");//前台为1
		if(id!=null && !"".equals(id)){
			resources.setId(Integer.parseInt(id));
			List<LResources> list = columnService.getListResources(resources);
			v.addAttribute("resources", list==null? new LResources() : list.get(0));
		}else{
			v.addAttribute("resources", new LResources());
		}
		
		return "houtai/columnAddAndUpdate";
	}
	@RequestMapping(value="/addCoumn",method=RequestMethod.POST)
	public String addCoumns(LResources resources,HttpServletResponse response,HttpServletRequest request) throws Exception{
		//resources.set
		columnService.addLResources(resources);
		return "redirect:/column";
	}
	@ResponseBody
	@RequestMapping(value="/del",method=RequestMethod.POST)
	public String del(LResources resources,HttpServletRequest request,HttpServletResponse response) throws Exception{
		int i = columnService.del(resources);
		return "0";
	}
}
